
//
//  WKAudioManager.swift
//  商家端Swift
//
//  Created by 天下宅 on 16/8/31.
//  Copyright © 2016年 天下宅. All rights reserved.
//

import Foundation
import AVFoundation
import AudioToolbox


class WKAudioManager:NSObject,AVAudioPlayerDelegate {
    static let sharedInstance : WKAudioManager = {
            let _audioManager = WKAudioManager()
            return _audioManager
        }()

    private var newOrderSoundID:SystemSoundID = 0
    private var thisOrderSoundID:SystemSoundID = 0

    private override init() {
        
        
        let orderPath = Bundle.main.path(forResource: "new_order_pusher", ofType: "caf")
        //地址转换
        let orderURL = NSURL(fileURLWithPath: orderPath!)
//        print(orderURL.absoluteString)
        //赋值
        AudioServicesCreateSystemSoundID(orderURL, &newOrderSoundID)
        
//        print(newOrderSoundID)
        
        let thisOrderPath = Bundle.main.path(forResource: "order_dispatch", ofType: "caf")
        //地址转换
        let failURL = NSURL(fileURLWithPath: thisOrderPath!)
        //赋值
        AudioServicesCreateSystemSoundID(failURL, &thisOrderSoundID)
        
        //播放声音
//        AudioServicesPlayAlertSound(soundID)

        

    }
    
    func playNewOrder() {
//        print("播放声音")
        AudioServicesPlayAlertSound(newOrderSoundID)//播放声音 + 震动
//        AudioServicesPlaySystemSound(newOrderSoundID)//播放声音
    }
    
    func playThisOrder() {
        AudioServicesPlaySystemSound(thisOrderSoundID)//播放声音

    }
    
}
